package com.nw.dsl4j.runtime.adapter;

import java.util.HashMap;
import java.util.Map;

public class AdapterSupportImpl implements Adaptable {
	
	Map<Class<?>, Object> adapters = new HashMap<Class<?>, Object>();
	
	public AdapterSupportImpl() {
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getAdapter(Class<? extends T> cls) {
		try {
			Object object = adapters.get(cls);
			if (object == null){
				object = cls.newInstance();
				adapters.put(cls, object);
			}
			return (T) object;
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@Override
	public String toString() {
		return adapters.entrySet().toString();
	}
	

}
